package collection;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 集合只能存放引用类型元素，并且存放的是元素的引用地址
 */
public class CollectionDemo4 {
    public static void main(String[] args) {
        Collection c = new java.util.ArrayList();
        Point p = new Point(1,2);
        c.add(p); //将p的值存入了集合，而p是引用类型变量，存的值是地址
        test(p,c);
//        System.out.println("p:"+p); //p:Point{x=1, y=2}
//        System.out.println("c:"+c); //c:[Point{x=1, y=2}]
//        p.setX(2);
        System.out.println("p:"+p); //p:Point{x=2, y=2}
        System.out.println("c:"+c); //c:[Point{x=2, y=2}]
    }

    public static void test(Point p,Collection c){
        p.setX(2);
        c.clear();
        p = new Point(3,4);
        c.add(p);
        c = new ArrayList();
        p = new Point(5,6);
        c.add(p);
        p.setX(7);

    }
}
















